//,editrules:{required:true,number:true,minValue:0,maxValue:1} 数字
$(function() {
	var initData = $("#initData").val();
	var ss = initData.split(",");
	initLoad(ss);
});

function initLoad(ss) {
	var cols = ['ID', '账户', '昵称', '头像','角色', '权限', '锁定', '注册时间', '操作'];
	var models = [{
		name: 'id',
		index: 'id',
		width: 200,
		fixed: true,
		key: true,
		search: false,
		editable: false,
		editoptions: {
			readonly: true
		}
	},
	{
		name: 'account',
		index: 'account',
		searchoptions: {
			'sopt': ['cn']
		},
		editable: true,
		editrules: {
			edithidden:true,
			required:true
		},
		editoptions: {
			size: 15
		}
	},
	{
		name: 'nickname',
		index: 'nickname',
		searchoptions: {
			'sopt': ['cn']
		},
		editable: true,
		editrules: {
            required: true
        },
        editoptions: {
            size: 15
        }
	},
	{
		name: 'pic',
		index: 'pic',
		search: false,
		align: 'center',
		width: 91,
		fixed: true,
		formatter: function(cv, op, rb) {
			if (cv != null) {
				return '<img src="' + cv + '" width="64px"/>';
			} else {
				return '';
			}
		}
	},
	{
		name: 'roles',
		index: 'roles',
		search: false,
		editable: true,
		edittype: "select",
		editoptions: {
			value: ss[0]
		}
	},
	{
		name: 'auths',
		index: 'auths',
		search: false,
		editable: true
	},
	{
		name: 'locked',
		index: 'locked',
		hidden: false,
		search: false,
		editable: true,
		edittype: "select",
		editoptions: {
			value: '0:正常;1:锁定'
		},
		formatter: function(cv, op, rb){
		    return cv == '0'?'正常':'锁定';
		}
	},

	{
		name: 'createTime',
		index: 'createTime',
		search: false,
		width: 200,
		formatter: function(cv, op, rb) {
			return num2Date(cv);
		}
	},
	{
		name: 'opt',
		index: 'id',
		search: false,
		formatter: function(cv, op, rb) {
			var html = '';
			if (rb.locked == '0') {
				html += '<a href="/master/user/lock/' + rb.id + '" class="btn btn-danger  btn-xs"><i class="fa fa-lock"></i>&nbsp;锁定</a>&nbsp;';
			} else {
				html += '<a href="/master/user/lock/' + rb.id + '" class="btn btn-info  btn-xs"><i class="fa fa-unlock"></i>&nbsp;解锁</a>&nbsp;';
			}
			return html;
		}
	}];

    var datas = {
        "sortorder": "ASC",
        "sortname":"id"
    };
	loadData("/master/user", "tabdiv", datas, cols, models);
}
